/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package player.model;

import java.io.Serializable;

/**
 * Track predstavlja jedan audio file
 * @author Andrej
 */
public class Track implements Serializable
{
    private String filename;
    private String trackName;
    private String artist;
    private String genre;
    private String album;
    private int length;
    private long bitrate;

    /**
     * Konstruktor
     */
    public Track()
    {
    }

    /**
     * Konstruktor sa parametrima
     * @param filename ime fajla
     * @param trackName ime tracka
     * @param artist artist
     * @param genre zanr tracka
     * @param album album
     */
    public Track(String filename, String trackName, String artist, String genre, String album)
    {
        this.filename = filename;
        this.trackName = trackName;
        this.artist = artist;
        this.genre = genre;
        this.album = album;
    }

    /**
     * Copy konstruktor
     * @param track track koji se kopira
     */
    public Track(Track track)
    {
        this.filename = track.filename;
        this.trackName = track.trackName;
        this.artist = track.artist;
        this.genre = track.genre;
        this.album = track.album;
    }

    /**
     * Geter albuma
     * @return ime albuma
     */
    public String getAlbum()
    {
        return album;
    }

    /**
     * Seter albuma
     * @param album ime albuma
     */
    public void setAlbum(String album)
    {
        this.album = album;
    }

    /**
     * Geter artista
     * @return ime artista
     */
    public String getArtist()
    {
        return artist;
    }

    /**
     * Seter artista
     * @param artist ime artista
     */
    public void setArtist(String artist)
    {
        this.artist = artist;
    }

    /**
     * Geter imena fajla
     * @return ime fajla
     */
    public String getFilename()
    {
        return filename;
    }

    /**
     * Seter imena fajla
     * @param filename ime fajla
     */
    public void setFilename(String filename)
    {
        this.filename = filename;
    }

    /**
     * Geter zanra
     * @return zanr
     */
    public String getGenre()
    {
        return genre;
    }

    /**
     * Seter zanra
     * @param genre zanr
     */
    public void setGenre(String genre)
    {
        this.genre = genre;
    }

    /**
     * Geter imena tracka
     * @return ime
     */
    public String getTrackName()
    {
        return trackName;
    }

    /**
     * Seter imena tracka
     * @param trackName ime
     */
    public void setTrackName(String trackName)
    {
        this.trackName = trackName;
    }

    /**
     * Geter duzine tracka
     * @return duzina tracka u sekundama
     */
    public int getLenght()
    {
        return length;
    }

    /**
     * Seter duzine tracka
     * @param lenght duzina tracka u sekundama
     */
    public void setLenght(int lenght)
    {
        this.length = lenght;
    }

    /**
     * Geter bitrejta
     * @return bitrejt
     */
    public long getBitrate()
    {
        return bitrate;
    }

    /**
     * Seter bitrejta
     * @param bitrate bitrejt
     */
    public void setBitrate(long bitrate)
    {
        this.bitrate = bitrate;
    }

    /**
     * Geter niza objekata
     * @return niz objekata sa atributima tracka
     */
    public Object[] toArray()
    {
        Object rec[] =
        {
            this.artist, this.trackName, this.getLengthAsString()
        };
        return rec;
    }

    /**
     * Vraca duzinu kao string
     * @return duzina tracka formatirana kao string
     */
    private String getLengthAsString()
    {
        String sec, min;
        if (this.length % 60 < 10)
        {
            sec = "0" + (this.length % 60);
        } else
        {
            sec = "" + (this.length % 60);
        }
        if (this.length / 60 < 10)
        {
            min = "0" + (this.length / 60);
        } else
        {
            min = "" + (this.length / 60);
        }

        return min + ":" + sec;
    }

    @Override
    public boolean equals(Object obj)
    {
        if(obj instanceof Track)
        {
            Track tr = (Track)obj;

            if(tr.getFilename().equals(this.filename))
            {
                return true;
            }
        }
        return false;
    }


    
    @Override
    public String toString()
    {
        return "Track{" + "filename=" + filename + "trackName=" + trackName + "artist=" + artist + "genre=" + genre + "album=" + album + '}';
    }

    

    
}
